using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ThreadExercise.methods
{
    public class ThreadMethod
    {
        public static void DoWork()/*  */
        {
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine($"子线程：{i}");
                Thread.Sleep(100);
            }
        }

        public static void DoWorkWithParam(object? param)
        {
            string message = param as string ?? "Default Message";
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine($"{message} - {i}");
                Thread.Sleep(200);
            }
        }

        public static void DoWorkWithTimes(object? param) 
        {
            int times = param is null ? 0:(int)param;
            Console.WriteLine($"循环次数： {times}");
            for (int i = 0; i < times; i++) 
            {
                Console.WriteLine($"循环第{i + 1}次");
                Thread.Sleep(200);
            }
            Console.WriteLine("循环结束");
        }

        public static void DoWorkWithCustomObject(object param)
        {
            People people = param as People ?? new People();
            Console.WriteLine("子线程：");
            people?.Print();
            Thread.Sleep(200);
        }

        
    }
}
